//
//  UITableViewCell+HDNewComCell.m
//  app
//
//  Created by D on 15/8/21.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDNewComCell.h"

static const CGFloat kMargin = 12.0f;
static const CGFloat kTitleW = 100.0f;
static const CGFloat kNameW = 60.0f;
static const CGFloat kPhoneW = 156.0f;
static const CGFloat kHight = 30.0f;

@implementation HDNewComCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier row:(NSInteger)row
{
    if (self = [super init]) {
        
        if (row == 0) {
            
            self.nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:120 oh:kHight])];
            self.nameLab.text = @"请选择您所在的小区";
            [self.nameLab setFont:[UIFont systemFontOfSize:13]];
            [self.nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            [self addSubview:self.nameLab];
            
            
        }
        else if (row == 1){
        
            self.nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:kNameW oh:kHight])];
            self.nameLab.text = @"省";
            [self.nameLab setFont:[UIFont systemFontOfSize:15]];
            [self.nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            [self addSubview:self.nameLab];
            
            CGFloat contentWitd = UBO_WINDOW.width - 24 - kNameW;
            
            self.contentLab = [[UILabel alloc]initWithFrame:CGRectOf([self.nameLab.ufo fx:1 fy:UB_1_2 oy:-kHight/2], [self.ubo ow:contentWitd oh:kHight])];
            self.contentLab.tag = 1;
            [self.contentLab setFont:[UIFont systemFontOfSize:15]];
            [self.contentLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            self.contentLab.text = @"山西省";
            //            if ([[[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"]length] > 0) {
            //                self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"];
            //            } else {
            //                self.contentLab.text = nil;
            //            }
            
            [self addSubview:self.contentLab];
            
        }
        else if (row == 2){
        
            self.nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:kNameW oh:kHight])];
            self.nameLab.text = @"市";
            [self.nameLab setFont:[UIFont systemFontOfSize:15]];
            [self.nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            [self addSubview:self.nameLab];
            
            CGFloat contentWitd = UBO_WINDOW.width - 24 - kNameW;
            
            self.contentLab = [[UILabel alloc]initWithFrame:CGRectOf([self.nameLab.ufo fx:1 fy:UB_1_2 oy:-kHight/2], [self.ubo ow:contentWitd oh:kHight])];
            self.contentLab.tag = 1;
            [self.contentLab setFont:[UIFont systemFontOfSize:15]];
            [self.contentLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            self.contentLab.text = @"太原市";
            
            //            if ([[[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"]length] > 0) {
            //                self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"];
            //            } else {
            //                self.contentLab.text = nil;
            //            }
            
            [self addSubview:self.contentLab];
            
            
        }
        else if (row == 3){
        
            self.nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:kNameW oh:kHight])];
            self.nameLab.text = @"城区";
            [self.nameLab setFont:[UIFont systemFontOfSize:15]];
            [self.nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            [self addSubview:self.nameLab];
            
            CGFloat contentWitd = UBO_WINDOW.width - 24 - kNameW;
            
            self.contentLab = [[UILabel alloc]initWithFrame:CGRectOf([self.nameLab.ufo fx:1 fy:UB_1_2 oy:-kHight/2], [self.ubo ow:contentWitd oh:kHight])];
            self.contentLab.tag = 1;
            [self.contentLab setFont:[UIFont systemFontOfSize:15]];
            [self.contentLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            self.contentLab.text = @"杏花岭区";
            
            //            if ([[[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"]length] > 0) {
            //                self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"];
            //            } else {
            //                self.contentLab.text = nil;
            //            }
            
            [self addSubview:self.contentLab];
            
        }
        else if (row == 4)
        {
            self.nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:kNameW oh:kHight])];
            self.nameLab.text = @"小区";
            [self.nameLab setFont:[UIFont systemFontOfSize:15]];
            [self.nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            [self addSubview:self.nameLab];
            
            CGFloat contentWitd = UBO_WINDOW.width - 24 - kNameW;
            
            self.contentLab = [[UILabel alloc]initWithFrame:CGRectOf([self.nameLab.ufo fx:1 fy:UB_1_2 oy:-kHight/2], [self.ubo ow:contentWitd oh:kHight])];
            self.contentLab.tag = 1;
            [self.contentLab setFont:[UIFont systemFontOfSize:15]];
            [self.contentLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            
//            if ([[[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"]length] > 0) {
//                self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"];
//            } else {
//                self.contentLab.text = nil;
//            }
            
            [self addSubview:self.contentLab];
        }
//        else if (row == 5){
//            self.nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:kNameW oh:kHight])];
//            self.nameLab.text = @"组团";
//            [self.nameLab setFont:[UIFont systemFontOfSize:15]];
//            [self.nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
//            [self addSubview:self.nameLab];
//            
//            CGFloat contentWitd = UBO_WINDOW.width - 24 - kNameW;
//            
//            self.contentLab = [[UILabel alloc]initWithFrame:CGRectOf([self.nameLab.ufo fx:1 fy:UB_1_2 oy:-kHight/2], [self.ubo ow:contentWitd oh:kHight])];
//            self.contentLab.tag = 2;
//            [self.contentLab setFont:[UIFont systemFontOfSize:15]];
//            [self.contentLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
//            
////            if ([[[[NSUserDefaults standardUserDefaults]objectForKey:@"community_zu"]objectForKey:@"group_name"]length] > 0) {
////                self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"community_zu"]objectForKey:@"group_name"];
////            } else {
////                self.contentLab.text = nil;
////            }
//            
//            [self addSubview:self.contentLab];
//            
//        }
        else if (row == 5){
            self.nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:kNameW oh:kHight])];
            self.nameLab.text = @"楼牌号";
            [self.nameLab setFont:[UIFont systemFontOfSize:15]];
            [self.nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            [self addSubview:self.nameLab];
            
            CGFloat contentWitd = UBO_WINDOW.width - 24 - kNameW;
            
            self.contentLab = [[UILabel alloc]initWithFrame:CGRectOf([self.nameLab.ufo fx:1 fy:UB_1_2 oy:-kHight/2], [self.ubo ow:contentWitd oh:kHight])];
            self.contentLab.tag = 3;
            [self.contentLab setFont:[UIFont systemFontOfSize:15]];
            [self.contentLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            
//            if ([[[[NSUserDefaults standardUserDefaults]objectForKey:@"building"]objectForKey:@"building_name"]length] > 0) {
//                self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"building"]objectForKey:@"building_name"];
//            } else {
//                self.contentLab.text = nil;
//            }
            
            [self addSubview:self.contentLab];
            
        }
        else if (row == 6){
            self.nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:kNameW oh:kHight])];
            self.nameLab.text = @"房间号";
            [self.nameLab setFont:[UIFont systemFontOfSize:15]];
            [self.nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            [self addSubview:self.nameLab];
            
            CGFloat contentWitd = UBO_WINDOW.width - 24 - kNameW;
            
            self.contentLab = [[UILabel alloc]initWithFrame:CGRectOf([self.nameLab.ufo fx:1 fy:UB_1_2 oy:-kHight/2], [self.ubo ow:contentWitd oh:kHight])];
            self.contentLab.tag = 4;
            [self.contentLab setFont:[UIFont systemFontOfSize:15]];
            [self.contentLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            
//            if ([[[[NSUserDefaults standardUserDefaults]objectForKey:@"house"]objectForKey:@"house_name"]length] > 0) {
//                self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"house"]objectForKey:@"house_name"];
//            } else {
//                self.contentLab.text = nil;
//            }
            
            [self addSubview:self.contentLab];
            
        }
        else if (row == 7){
            self.namefld = [[UITextField alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kHight/2], [self.ubo ow:180 oh:kHight])];
            self.namefld.placeholder = @"请输入接受验证码的手机号";
            [self.namefld setFont:[UIFont systemFontOfSize:15]];
            [self.namefld setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
            self.namefld.delegate = self;
            self.namefld.returnKeyType = UIReturnKeyGo;
//            [self.namefld addTarget:self action:@selector(viewSendToController:) forControlEvents:UIControlEventTouchUpInside];
            
//            if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"comPhone"]integerValue] > 0) {
//                self.namefld.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"comPhone"];
//            }
            
            [self addSubview:self.namefld];
 
            
        }
    
        
        
    }
    return self;
}


- (void)valueForCellWithRow:(NSInteger)row
{
    if (row == 4)
    {
            self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"community"]objectForKey:@"community_name"];
        
    }
//    else if (row == 5){
//            self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"community_zu"]objectForKey:@"group_name"];
//
//        
//        
//    }
    else if (row == 5){
            self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"building"]objectForKey:@"building_name"];
  
        
        
    }
    else if (row == 6){
        
            self.contentLab.text = [[[NSUserDefaults standardUserDefaults]objectForKey:@"house"]objectForKey:@"house_name"];
 
        
        
    }
    else if (row == 7){
            self.namefld.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"comPhone"];
    
        
    }
    
}


-(void)textFieldDidEndEditing:(UITextField *)textField
{
    
    if ([[[[NSUserDefaults standardUserDefaults]objectForKey:@"house"] objectForKey:@"house_name"]length] > 0){
        
        if (self.namefld.text.length == 11) {
            [self.namefld resignFirstResponder];
            [[NSUserDefaults standardUserDefaults] setObject:self.namefld.text forKey:@"comPhone"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }else
        {
            [self.namefld resignFirstResponder];
            UIAlertView * av = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请输入正确的电话号码" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [av show];
        }
        
    }else
    {
        UIAlertView * av = [[UIAlertView alloc]initWithTitle:@"请选择小区" message:nil delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
        [av show];
    }

    
    
    
    
    
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(next)]) {
        [self.delegate next];
    }
    
    return YES;
}

@end





